﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<GabageFactory.Models.EventRecordDetail>" %>
<%@ Import Namespace="System.Collections.Generic" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	创建事件
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <script type="text/javascript">
        function setCenter(Xelement) {
            var parent = Xelement.parentNode;
            parent.style.position = "relative";
            Xelement.style.position = "absolute";
            var left = (parent.clientWidth - Xelement.clientWidth) / 2;
            var top = (parent.clientHeight - Xelement.clientHeight) / 2;
            Xelement.style.left = left + "px";
            Xelement.style.top = top + "px";
        }
    </script>
    
    <% 
        User user = (User)ViewData["user"];
        EventDailyRecord dailyRecord = (EventDailyRecord) ViewData["dailyRecord"];
        string[] types = (string[])ViewData["types"];
        string[] priorities = (string[])ViewData["priorites"];
        using (Html.BeginForm())
    {%>
        <%= Html.ValidationSummary(true) %>
        <%= Html.Hidden("eventId", Model.Id)%>
        <%= Html.Hidden("id", dailyRecord.Id)%>
        <%= Html.Hidden("status", Model.Status)%>
            
    <table cellpadding="4" cellspacing="0" class="com_detail_table" style="width:756px;">
        <tr>
            <th colspan="8">跟踪事件</th>
        </tr>
        <tr>
            <td class="lab">事件名称：</td>
            <td colspan="7"><%=Model.Name%></td>
        </tr>
        <tr>
            <td class="lab">事件现场：</td>
            <td colspan="7">
                <%=Model.StackName %>
            </td>
        </tr>
        <tr>
            <td class="lab">开始时间：</td>
            <td><%=Model.OccurredDate.ToString("yyyy-MM-dd HH:mm")%></td>
            <td class="lab">事件类别：</td>
            <td><%=types[Model.Type] %></td>
            <td class="lab">事件级别：</td>
            <td><%=priorities[Model.Priority] %></td>
            <td class="lab">上报人：</td>
            <td><%=Model.UserName%></td>
        </tr>
        <tr>
            <td class="lab">记录时间：</td>
            <td colspan="7"><%=Html.TextBox("occurredDate", dailyRecord.OccurredDate)%></td>
        </tr>
        <tr>
            <td class="lab">进展情况：</td>
            <td colspan="7"><%=Html.TextArea("EventDesc", dailyRecord.Description, new { rows = 5, cols = 70 })%></td>
        </tr>
        <tr>
            <td class="lab">进度评估：</td>
            <td colspan="7">
                <select id="progress" name="progress" onchange= "changeProgress();">
                    <%
                        int i = 0;
                        for (i = 0; i <= 20; i++)
                        {
                    %>
                    <option value="<%=5 * i %>" <%if(dailyRecord.Progress == (5 * i)){ %> selected="selected" <%} %>><%=5 * i %>%</option>
                    <%} %>
                </select>
            </td>
        </tr>
        <tr>
           <td class="lab">现场图片：</td>
           <td colspan="7">
                <div id="addPicButton" style="display:block"><input type="file" name="file_upload" id="file_upload" /></div>
           </td>
        </tr>
        <tr>
           <td class="lab">&nbsp;</td>
           <td colspan="7" id="pics">
                <div id="pic1Area" style="<% if (string.IsNullOrEmpty(dailyRecord.Pic1)) {%>display:none;<%} %>clear:both;margin-top:10px">
                  <input type="hidden" id="picPath1" name="picPath1" value="<%=dailyRecord.Pic1 %>" />
                  <div style="border:1px solid #e4e4e4;float:left;width:100px;height:75px;text-align:center;line-height:75px;"><img id="pic1" src="<% if (string.IsNullOrEmpty(dailyRecord.Pic1)) {%>../../Content/empty.png<%}else{ %><%=Url.Content(dailyRecord.Pic1) %><%} %>" alt="" onload="setCenter(this)" class="thumbnail" /></div>
                  <div style="margin-left:10px;float:left">
                      <div style="float:left"><textarea id="picDes1" name="picDes1" rows="5" cols="48" style="height:75px"><%= dailyRecord.Pic1_desc%></textarea></div>
                      <div style="float:left">
                          <p style=" margin-bottom:10px;">
                            <input type="button" class="uploadify-button2" value="删  除" onclick="delPic(1);" />
                          </p>
                          <input type="file" name="file_upload1" id="file_upload1" />
                      </div>
                  </div>
                </div>
                <div id="pic2Area" style="<% if (string.IsNullOrEmpty(dailyRecord.Pic2)) {%>display:none;<%} %>clear:both;margin-top:10px">
                  <input type="hidden" id="picPath2" name="picPath2" value="<%=dailyRecord.Pic2 %>" />
                  <div style="border:1px solid #e4e4e4;float:left;width:100px;height:75px;text-align:center;line-height:75px;"><img id="pic2" src="<% if (string.IsNullOrEmpty(dailyRecord.Pic2)) {%>../../Content/empty.png<%}else{ %><%=Url.Content(dailyRecord.Pic2) %><%} %>" alt="" onload="setCenter(this)" class="thumbnail" /></div>
                  <div style="margin-left:10px;float:left">
                      <div style="float:left"><textarea id="picDes2" name="picDes2" rows="5" cols="48" style="height:75px"><%= dailyRecord.Pic2_desc%></textarea></div>
                      <div style="float:left">
                          <p style=" margin-bottom:10px;">
                            <input type="button" class="uploadify-button2" value="删  除" onclick="delPic(2);" />
                          </p>
                          <input type="file" name="file_upload2" id="file_upload2" />
                      </div>
                  </div>
                </div>
                <div id="pic3Area" style="<% if (string.IsNullOrEmpty(dailyRecord.Pic3)) {%>display:none;<%} %>clear:both;margin-top:10px">
                  <input type="hidden" id="picPath3" name="picPath3" value="<%=dailyRecord.Pic3 %>" />
                  <div style="border:1px solid #e4e4e4;float:left;width:100px;height:75px;text-align:center;line-height:75px;"><img id="pic3" src="<% if (string.IsNullOrEmpty(dailyRecord.Pic3)) {%>../../Content/empty.png<%}else{ %><%=Url.Content(dailyRecord.Pic3) %><%} %>" alt="" onload="setCenter(this)" class="thumbnail" /></div>
                  <div style="margin-left:10px;float:left">
                      <div style="float:left"><textarea name="picDes3" id="picDes3" rows="5" cols="48" style="height:75px"><%= dailyRecord.Pic3_desc%></textarea></div>
                      <div style="float:left">
                          <p style=" margin-bottom:10px;">
                            <input type="button" class="uploadify-button2" value="删  除" onclick="delPic(3);" />
                          </p>
                          <input type="file" name="file_upload3" id="file_upload3" />
                      </div>
                  </div>
                </div>
                <div id="pic4Area" style="<% if (string.IsNullOrEmpty(dailyRecord.Pic4)) {%>display:none;<%} %>clear:both;margin-top:10px">
                  <input type="hidden" id="picPath4" name="picPath4" value="<%=dailyRecord.Pic4 %>" />
                  <div style="border:1px solid #e4e4e4;float:left;width:100px;height:75px;text-align:center;line-height:75px;"><img id="pic4" src="<% if (string.IsNullOrEmpty(dailyRecord.Pic4)) {%>../../Content/empty.png<%}else{ %><%=Url.Content(dailyRecord.Pic4) %><%} %>" alt="" onload="setCenter(this)" class="thumbnail" /></div>
                  <div style="margin-left:10px;float:left">
                      <div style="float:left"><textarea name="picDes4" id="picDes4" rows="5" cols="48" style="height:75px"><%= dailyRecord.Pic4_desc%></textarea></div>
                      <div style="float:left">
                        <p style=" margin-bottom:10px;">
                            <input type="button" class="uploadify-button2" value="删  除" onclick="delPic(4);" />
                        </p>
                        <input type="file" name="file_upload4" id="file_upload4" />
                      </div>
                  </div>
                </div>
           </td>
        </tr>
    </table>
    
    <div class="submit_btn_area" style="margin-left:112px;">
        <input type="submit"id="submit" onclick="return validateForm();" value="提 交" />

        <input type="button" id="endButton" onclick="endEvent();" value="结束事件" />
    </div>
    <% } %>



    <script type="text/javascript" src="../../Scripts/jquery.uploadify-3.1.min.js"></script>
    <script type="text/javascript" language="javascript">
        function endEvent() {
            $("#status").val(1);
            if (validateForm())
            {
               $("#submit").click();
            }
        }
        
        $('#occurredDate').datetimepicker({
            showSecond: false,
            timeFormat: 'hh:mm'
        });

        

        var picNum = <%=dailyRecord.PicNum %>;

        var picFlags = [<%if(string.IsNullOrEmpty(dailyRecord.Pic1)) {%>false<%}else{ %>true<%} %>,<%if(string.IsNullOrEmpty(dailyRecord.Pic2)){%>false<%}else{ %>true<%} %>,<%if(string.IsNullOrEmpty(dailyRecord.Pic3)){ %>false<%}else{ %>true<%} %>,<%if(string.IsNullOrEmpty(dailyRecord.Pic4)){ %>false<%}else{ %>true<%} %>];

        $(function () {
            $("#file_upload").uploadify({
                'fileObjName': 'file',
                'multi': false,
                'buttonText': '添加图片',
                'buttonClass': 'submit_btn_area',
                'fileSizeLimit': '200KB',
                'fileTypeDesc': 'Jpeg Files',
                'fileTypeExts': '*.jpeg; *.jpg',
                'swf': '<%=Url.Content("~/Content/uploadify.swf") %>',
                'uploader': '<%=Url.Content("~/Event/FileUpload") %>',
                'onUploadSuccess': function (file, data, response) {
                    var result = eval("(" + data + ")");
                    if (result.error != "") {
                        alert(result.error);
                        return;
                    }
                    showPic(result.url);
                },
                'onUploadError': function (file, errorCode, errorMsg, errorString) {
                    alert('添加图片失败，请重新添加');
                }

            });

            $("#file_upload1").uploadify({
                'fileObjName': 'file',
                'multi': false,
                'buttonText': '重新上传',
                'buttonClass': 'submit_btn_area',
                'fileSizeLimit': '200KB',
                'fileTypeDesc': 'Jpeg Files',
                'fileTypeExts': '*.jpeg; *.jpg',
                'swf': '<%=Url.Content("~/Content/uploadify.swf") %>',
                'uploader': '<%=Url.Content("~/Event/FileUpload") %>',
                'onUploadSuccess': function (file, data, response) {
                    var result = eval("(" + data + ")");
                    if (result.error != "") {
                        alert(result.error);
                        return;
                    }
                    replacePic(1, result.url);
                },
                'onUploadError': function (file, errorCode, errorMsg, errorString) {
                    alert('添加图片失败，请重新添加');
                }

            });

            $("#file_upload2").uploadify({
                'fileObjName': 'file',
                'multi': false,
                'buttonText': '重新上传',
                'buttonClass': 'submit_btn_area',
                'fileSizeLimit': '200KB',
                'fileTypeDesc': 'Jpeg Files',
                'fileTypeExts': '*.jpeg; *.jpg',
                'swf': '<%=Url.Content("~/Content/uploadify.swf") %>',
                'uploader': '<%=Url.Content("~/Event/FileUpload") %>',
                'onUploadSuccess': function (file, data, response) {
                    var result = eval("(" + data + ")");
                    if (result.error != "") {
                        alert(result.error);
                        return;
                    }
                    replacePic(2, result.url);
                },
                'onUploadError': function (file, errorCode, errorMsg, errorString) {
                    alert('添加图片失败，请重新添加');
                }

            });

            $("#file_upload3").uploadify({
                'fileObjName': 'file',
                'multi': false,
                'buttonText': '重新上传',
                'buttonClass': 'submit_btn_area',
                'fileSizeLimit': '200KB',
                'fileTypeDesc': 'Jpeg Files',
                'fileTypeExts': '*.jpeg; *.jpg',
                'swf': '<%=Url.Content("~/Content/uploadify.swf") %>',
                'uploader': '<%=Url.Content("~/Event/FileUpload") %>',
                'onUploadSuccess': function (file, data, response) {
                    var result = eval("(" + data + ")");
                    if (result.error != "") {
                        alert(result.error);
                        return;
                    }
                    replacePic(3, result.url);
                },
                'onUploadError': function (file, errorCode, errorMsg, errorString) {
                    alert('添加图片失败，请重新添加');
                }

            });

            $("#file_upload4").uploadify({
                'fileObjName': 'file',
                'multi': false,
                'buttonText': '重新上传',
                'buttonClass': 'submit_btn_area',
                'fileSizeLimit': '200KB',
                'fileTypeDesc': 'Jpeg Files',
                'fileTypeExts': '*.jpeg; *.jpg',
                'swf': '<%=Url.Content("~/Content/uploadify.swf") %>',
                'uploader': '<%=Url.Content("~/Event/FileUpload") %>',
                'onUploadSuccess': function (file, data, response) {
                    var result = eval("(" + data + ")");
                    if (result.error != "") {
                        alert(result.error);
                        return;
                    }
                    replacePic(4, result.url);
                },
                'onUploadError': function (file, errorCode, errorMsg, errorString) {
                    alert('添加图片失败，请重新添加');
                }

            });
        });

        function delFile(filePath) {
            $.ajax({  
                type: "POST",  
                url: '<%=Url.Content("~/Event/DelFile") %>',  
                data: { "file": filePath }
            }).done(function( msg ) {});
        }

        function delPic(index) {
            picNum--;
            picFlags[index - 1] = false;
            $("#pic" + index + "Area").css("display", "none");
            $("#pic" + index).attr("src", "../../Content/empty.png");
            delFile($("#picPath" + index).val());
            $("#picPath" + index).val("");
            $("#picDes" + index).val("");
            $("#addPicButton").css("display", "");
        }

        function showPic(url) {
            picNum++;
            var i = 0;
            for (i = 0; i < 4; i++) {
                if (picFlags[i] == false) {
                    picFlags[i] = true;
                    $("#pic" + (i + 1) + "Area").css("display", "block");
                    $("#pic" + (i + 1)).attr("src", url);
                    $("#picPath" + (i + 1)).val(url);
                    break;
                }
            }

            if (picNum >= 4) {
                $("#addPicButton").css("display", "none");
            }
        }

        function replacePic(index, url) {
            $("#pic" + index).attr("src", url);
            $("#picPath" + index).val(url);
        }

        function changeProgress() {
             var progress = document.getElementById("progress").value;
             if(progress == 100) {
                 $("#submit").css("display", "none");
                 $("#endButton").css("display", "");
             }
             else {
                 $("#submit").css("display", "");
                 $("#endButton").css("display", "none");
             }
        }

        changeProgress();

        function validateForm() {
            var eOccuredDate = Date.parse('<%=Model.OccurredDate.Date %>'.replace(/-/g,"/"));
            var occuredDate = $('#occurredDate').val();

            if (occuredDate == null || occuredDate == '' || occuredDate == 'undefined' || Date.parse(occuredDate.replace(/-/g,"/")) < eOccuredDate)
            {
                alert("跟踪日期不能早于事件发生日期<%=Model.OccurredDate.Date.ToString("yyyy-MM-dd") %>");
                $('#occurredDate').focus();
                return false;
            }

            if ($("#status").val() == 1 && document.getElementById("progress").value != 100) {
                alert("事件已经结束，进度应为100%");
                $('#progress').focus();
                return false;
            }

            return true;
        }
    </script>
</asp:Content>
